package cn.edu.ujn.lab.controller;

import cn.edu.ujn.lab.dao.LendList;
import cn.edu.ujn.lab.service.ILenListService;
import cn.edu.ujn.lab.service.LendListServiceImpl;
import cn.edu.ujn.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.util.pattern.PathPattern;

import java.util.List;

@Controller
public class LendListController {

    @Autowired
    private ILenListService lenListService;

    //分页
    @GetMapping("/lendList/list.action")
    public String list(Model model, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer rows,
                       LendList lendList) {
        lendList.setStart(rows*(page-1));
        lendList.setRows(rows);
        Page<LendList> page1 = lenListService.selectAll(lendList);
        model.addAttribute("page",page1);
        return "lendList";
    }

    //查找
    @RequestMapping("/lendList/getLendListById.action")
    @ResponseBody
    public LendList findById(@PathVariable("id") @RequestParam Integer id){
        return lenListService.findById(id);
    }

    //删除
    @RequestMapping("/lendList/delete.action")
    @ResponseBody
    public Integer deleteById(@PathVariable("id")  @RequestParam Integer id){
        return lenListService.delete(id);
    }
    //增加
    @PostMapping("/lendList/create.action")
    @ResponseBody
    public LendList add(LendList lendList){
        return lenListService.insert(lendList);
    }
    //更新
    @PostMapping("/lendList/update.action")
    @ResponseBody
    public LendList update(LendList lendList){
        return lenListService.update(lendList);
    }

    //查找全部
    @GetMapping("/lendList")
    @ResponseBody
    public List<LendList> findAll(){
        return  lenListService.findAll();
    }


}
